<template>
  <div class="tb-container">
    <el-card>
      <search-tool @onSearch="handleSearch"></search-tool>
      <el-table
        v-loading="loading"
        :data="tableData"
        style="width: 100%"
        height="528px"
      >
        <el-table-column label="序号" type="index" width="80" />
        <el-table-column prop="equipmentName" label="设备名称" width="130">
          <template #default="{ row }">
            <span>{{ row.equipmenmonitorForm.equipmentName }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="equipmentNo" label="设备编号" width="160">
          <template #default="{ row }">
            <span>{{ row.equipmenmonitorForm.equipmentNo }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="pipeInfoName" label="所属管廊" width="160">
        </el-table-column>
        <el-table-column prop="warehouseName" label="所属仓室" width="160">
        </el-table-column>
        <el-table-column prop="subregionName" label="防火分区" width="160">
        </el-table-column>
        <el-table-column prop="alarmDesc" label="告警描述" width="160">
          <template #default="{ row }">
            <span>{{ row.equipmenmonitorForm.alarmDesc }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="alarmTime" label="告警时间" width="160">
          <template #default="{ row }">
            <span>{{ row.equipmenmonitorForm.alarmTime }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="dealStatus" label="当前状态" width="140">
          <template #default="{ row }">
            <span>{{ row.equipmenmonitorForm.dealStatus }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200">
          <template #default="{ row }">
            <div>
              <svg-icon
                style="cursor: pointer; color: #547bf1"
                icon="run-product-view"
                @click="handleView(row)"
              ></svg-icon>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        class="pagination"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page"
        :page-sizes="[5, 10, 20]"
        :page-size="size"
        layout="->,prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
      <view-dialog
        :title="dialogTitle"
        :rowData="curRowData"
        :srcList="srcList"
        :photoList="photoList"
        v-model:visible="visibleView"
        @onReload="reloadPage"
      ></view-dialog>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import SearchTool from './components/SearchTool/index.vue'
import viewDialog from './components/ViewDialog/index.vue'
import {
  userList,
  equipmenmonitor,
  editStatus,
  equipmentQuery,
  photaQuery
} from '@/api/monitor.js'

const equipmenmonitorForm = ref({})
const visibleView = ref(false)
const curRowData = ref({})
const dialogTitle = ref('')
const tableData = ref([])
const total = ref(0)
const page = ref(1)
const size = ref(8)
const params = ref({})
const loading = ref(false)
const alarmNo = ref('')
const listData = ref({})
const rowList = ref({})
const srcList = ref([])
const photoList = ref([])
const userInfo = ref({})
const getUserInfo = async () => {
  const res = await userList()
  userInfo.value = res
}
getUserInfo()

// 查询数据
const getListData = async (params) => {
  loading.value = true
  const res = await equipmenmonitor(params, page.value, size.value)
  tableData.value = res.rows
  equipmenmonitorForm.value = res.rows.equipmenmonitorForm
  total.value = res.total
  loading.value = false
}
getListData(params.value)

const list = async (alarmNo) => {
  listData.value = await equipmentQuery(alarmNo)
  rowList.value.dispose = listData.value.dispose
    ? listData.value.dispose
    : false
  if (rowList.value.dispose.id) {
    const res = await photaQuery(rowList.value.dispose.id)
    photoList.value = res
    res.forEach((item) => {
      srcList.value.push(item.file_url)
    })
  }
}

const reloadPage = () => {
  getListData(params.value)
  if (visibleView.value) {
    visibleView.value = false
  }
}
reloadPage()

//查询条件相关
const handleSearch = (paramsData) => {
  params.value = paramsData
  getListData(paramsData)
}
// 分页相关
/**
 * size 改变触发
 */
const handleSizeChange = (currentSize) => {
  size.value = currentSize
  getListData(params.value)
}

/**
 * 页码改变触发
 */
const handleCurrentChange = (currentPage) => {
  page.value = currentPage
  getListData(params.value)
}
const handleView = (row) => {
  dialogTitle.value = '全流程查看'
  curRowData.value = row
  // console.log(row)
  list(row.equipmenmonitorForm.alarmNo)
  alarmNo.value = row.equipmenmonitorForm.alarmNo
  console.log('index', row.equipmenmonitorForm.alarmNo)
  visibleView.value = true
}
</script>

<style lang="scss" scoped>
.tb-container {
  :deep(.el-table th.el-table__cell) {
    background-color: #e4edff;
  }
}
</style>
